#pragma once
#include "base/function.h"
#include "base/logbuffer.h"

#include <stdio.h>
#include <time.h>

#include <string>

namespace net_tools
{
  class Eventloop;
  namespace base
  {
    class Logfile
    {
    public:
      Logfile(std::string app_name, net_tools::Eventloop *eventloop, FILE *file_stream);
      ~Logfile();
      void Use_file_flush_file();
      void Setstream(FILE *stream);
      void Flush();
      void Output(void *address, short int len);

    private:
      void Creatfile();
      void Endfile();
      void Rollfile();
      std::string app_name_;
      net_tools::Eventloop *eventloop_;
      pid_t pid_;
      timeval begin_time_;
      timeval end_time_;
      uint64_t index_;
      char tm_buf[128];
      std::string filename_;
      FILE *fd_stream_;
      Logbuffer logbuffer_;
      bool use_file_;
      size_t write_size_;
    };

  } // namespace base
} // namespace net_tools
